package com.zone.lib.download.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInstaller;
import android.os.Build;

import androidx.annotation.RequiresApi;

import com.zone.lib.download.cons.Constants;


public class InstallResultReceiver extends BroadcastReceiver {


    private static final String TAG = "InstallResultReceiver";

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
            Intent installIntent=new Intent();
            installIntent.setAction(Constants.INSTALL_INTENT_ACTION);
            if (status == PackageInstaller.STATUS_SUCCESS) {
//                Log.e(TAG, "success");
                installIntent.putExtra(Constants.INSTALL_INTENT_EXTRA,1);
            } else {
                installIntent.putExtra(Constants.INSTALL_INTENT_EXTRA,0);
//                Log.e(TAG, intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE));
            }
            context.sendBroadcast(installIntent);
        }
    }
}